Paradigm(s) | Concurrent programming, multi-core, imperative |
---|---|
Appeared in | 2005 |
Typing discipline | strong, static |
Major implementations | xcc |
Influenced by | C, Communicating Sequential Processes, Occam |
Usual filename extensions | .xc |
Website | http://www.xmos.com/published/programming-xc-xmos-devices |
The XC Programming Language is a computer programming language developed by XMOS.
XC is an imperative programming language with a computational framework based on C. XC programs consist of functions that execute statements that act upon values stored in variables. Control-flow statements express decisions, and looping statements express iteration[1].
The language was designed to exploit the XMOS processor architecture[2], but is a general-purpose language and implementations for other architectures are in construction. Running XC on other platforms is currently supported by highly-optimised interpretation of the XMOS instruction set.
Contents |
One of the most unusual features of XC is the inclusion of timers and ports in a high-level programming language. One of the great historical weaknesses of high-level programming languages - particularly those based on formal theoretical frameworks such as process calculi or those based on functional programming - is the inability to combine clean high-level constructs with efficient and safe input-output.
The following is the XC source for the Hello World program.
# include < stdio .h > main ( void ) { printf ( " Hello , world !\ n " ); }
The language permits explicit parallelism, as well as parallel replication.
# include < platform .h > on stdcore [0] : out port tx = XS1_PORT_1A ; on stdcore [0] : in port rx = XS1_PORT_1B ; on stdcore [1] : out port lcdData = XS1_PORT_32A ; on stdcore [2] : in port keys = XS1_PORT_8B ; int main ( void ) { par { on stdcore [0] : uartTX ( tx ); on stdcore [0] : uartRX ( rx ); on stdcore [1] : lcdDrive ( lcdData ); on stdcore [2] : kbListen ( keys ); } }
Concurrent processes can communicate using channels.
# include < platform .h > on stdcore [0] : out port tx = XS1_PORT_1A ; on stdcore [1] : in port keys = XS1_PORT_8B ; void uartTX ( chanend dataIn , port tx ) { char data ; while (1) { dataIn :> data ; transmitByte ( tx , data ); } } void kbListen ( chanend c , port keys ) { char data ; while (1) { data = waitForKeyStroke ( keys ); c <: data ; } } int main ( void ) { chan c ; par { on stdcore [0] : uartTX (c , tx ); // Thread X on stdcore [1] : kbListen (c , keys ); // Thread Y } }
Edsger Dijkstra's guarded commands also feature.
More unconventionally, the language includes the use of ports - which can be used to directly control hardware pins from high-level software.
# include < xs1 .h > out port p = XS1_PORT_1A ; int main ( void ) { p <: 1; p <: 0; }
The language design was heavily influenced[3] by Communicating Sequential Processes - a process algebra developed by Tony Hoare, and therefore includes explicit parallelism and channel communication. Edsger Dijkstra can also claim an influence with the inclusion of guarded commands.
Because of its relations to CSP, the framework for modelling from CSP can be used to reason about XC programs[4].
As a result the language bears semantic (though not structural) similarities to languages such as occam. This is not surprising as one of the chief XC language designers was David May who also created occam.